﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace ApiCoreProject.Model.Entities
{
    public partial class BaseDBContext : DbContext
    {
        public BaseDBContext()
        {
        }

        public BaseDBContext(DbContextOptions<BaseDBContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Authority> Authorities { get; set; }
        public virtual DbSet<Department> Departments { get; set; }
        public virtual DbSet<Image> Images { get; set; }
        public virtual DbSet<Menu> Menus { get; set; }
        public virtual DbSet<Role> Roles { get; set; }
        public virtual DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=127.0.0.1;database=BaseDB;uid=sa;pwd=123;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Authority>(entity =>
            {
                entity.HasKey(e => e.AuthId);

                entity.ToTable("Authority");

                entity.Property(e => e.AuthId).HasColumnName("authID");

                entity.Property(e => e.MenuId).HasColumnName("menuID");

                entity.Property(e => e.RoleId).HasColumnName("roleID");

                entity.Property(e => e.Sort).HasColumnName("sort");

                entity.HasOne(d => d.Menu)
                    .WithMany(p => p.Authorities)
                    .HasForeignKey(d => d.MenuId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Authority_Menus");

                entity.HasOne(d => d.Role)
                    .WithMany(p => p.Authorities)
                    .HasForeignKey(d => d.RoleId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Authority_Roles");
            });

            modelBuilder.Entity<Department>(entity =>
            {
                entity.HasKey(e => e.DeptId);

                entity.ToTable("Department");

                entity.Property(e => e.DeptId).HasColumnName("deptID");

                entity.Property(e => e.DeptName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("deptName");

                entity.Property(e => e.LastTime)
                    .HasColumnType("datetime")
                    .HasColumnName("lastTime");

                entity.Property(e => e.Remark)
                    .HasMaxLength(500)
                    .IsUnicode(false)
                    .HasColumnName("remark");

                entity.Property(e => e.Type).HasColumnName("type");
            });

            modelBuilder.Entity<Image>(entity =>
            {
                entity.HasKey(e => e.ImgId);

                entity.Property(e => e.ImgId).HasColumnName("imgID");

                entity.Property(e => e.Extension)
                    .IsRequired()
                    .HasMaxLength(10)
                    .IsUnicode(false)
                    .HasColumnName("extension");

                entity.Property(e => e.Modular)
                    .HasColumnName("modular")
                    .HasDefaultValueSql("((1))");

                entity.Property(e => e.Path)
                    .IsRequired()
                    .HasMaxLength(200)
                    .IsUnicode(false)
                    .HasColumnName("path");

                entity.Property(e => e.Size).HasColumnName("size");

                entity.Property(e => e.Title)
                    .IsRequired()
                    .HasMaxLength(100)
                    .IsUnicode(false)
                    .HasColumnName("title");
            });

            modelBuilder.Entity<Menu>(entity =>
            {
                entity.Property(e => e.MenuId).HasColumnName("menuID");

                entity.Property(e => e.HrefUrl)
                    .IsRequired()
                    .HasMaxLength(200)
                    .IsUnicode(false)
                    .HasColumnName("hrefUrl");

                entity.Property(e => e.Icon)
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("icon");

                entity.Property(e => e.MenuName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("menuName");

                entity.Property(e => e.ParentId).HasColumnName("parentID");

                entity.Property(e => e.VueUrl)
                    .HasMaxLength(200)
                    .IsUnicode(false)
                    .HasColumnName("vueUrl");
            });

            modelBuilder.Entity<Role>(entity =>
            {
                entity.Property(e => e.RoleId).HasColumnName("roleID");

                entity.Property(e => e.DeptId).HasColumnName("deptID");

                entity.Property(e => e.LastTime)
                    .HasColumnType("datetime")
                    .HasColumnName("lastTime");

                entity.Property(e => e.Remark)
                    .IsRequired()
                    .HasMaxLength(20)
                    .IsUnicode(false)
                    .HasColumnName("remark");

                entity.Property(e => e.RoleName)
                    .IsRequired()
                    .HasMaxLength(20)
                    .IsUnicode(false)
                    .HasColumnName("roleName");

                entity.Property(e => e.Type).HasColumnName("type");

                entity.HasOne(d => d.Dept)
                    .WithMany(p => p.Roles)
                    .HasForeignKey(d => d.DeptId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Roles_Department");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.Property(e => e.UserId).HasColumnName("userID");

                entity.Property(e => e.ImgId).HasColumnName("imgID");

                entity.Property(e => e.LastTime)
                    .HasColumnType("datetime")
                    .HasColumnName("lastTime");

                entity.Property(e => e.LoginName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("loginName");

                entity.Property(e => e.LoginPwd)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("loginPwd");

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("name");

                entity.Property(e => e.Phone)
                    .IsRequired()
                    .HasMaxLength(20)
                    .IsUnicode(false)
                    .HasColumnName("phone");

                entity.Property(e => e.RoleId).HasColumnName("roleID");

                entity.Property(e => e.Sex)
                    .IsRequired()
                    .HasMaxLength(2)
                    .IsUnicode(false)
                    .HasColumnName("sex")
                    .IsFixedLength(true);

                entity.Property(e => e.Status).HasColumnName("status");

                entity.HasOne(d => d.Img)
                    .WithMany(p => p.Users)
                    .HasForeignKey(d => d.ImgId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Users_Images");

                entity.HasOne(d => d.Role)
                    .WithMany(p => p.Users)
                    .HasForeignKey(d => d.RoleId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Users_Roles");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
